<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    用户名：<input type="text" id="username"><br>
    密码：<input type="text" id="password"><br>
    <input type="checkbox" id="check"><label for="check">记住账号密码7天</label>
    <input type="button" id="btn" value="登录">
</body>
<script>
    
    const oun = document.getElementById("username");
    const opw = document.getElementById("password");
    const obtn = document.getElementById("btn");
    const ocheck = document.getElementById("check");

    // 读取本地存储中的用户数据，处理默认数据
    const userMsg = localStorage.getItem("userMsg") ? JSON.parse(localStorage.getItem("userMsg")) : {username:"",password:""};
    
    // 根据读取的数据，填充输入框
    oun.value = userMsg.username;
    opw.value = userMsg.password;

    // 点击登录
    obtn.onclick = function(){
        // console.log(ocheck.checked);
        // 判断是否选中复选框
        if(ocheck.checked){
            // 打包用户名和密码
            const obj = {
                username:oun.value,
                password:opw.value
            }
            // 将用户信息，存储到本地存储
            localStorage.setItem("userMsg", JSON.stringify(obj));
        }
    }


</script>
</html>